#ifndef _BUOLA_WIDGETS_CFILELISTFILLER_H_
#define _BUOLA_WIDGETS_CFILELISTFILLER_H_

#include <buola/io/curi.h>
#include <buola/io/cfolder.h>
#include <buola/threads/csyncqueue.h>
#include <buola/utility/uevent.h>
#include <buola/widgets/cfilelist.h>

namespace buola { namespace gui {

class CFileListFillerAction
{
public:
    int mCode;
    io::CURI mURI;
};

class CFileListFiller : public UUncopiable
{
public:
    CFileListFiller(CFileList*,const io::CURI &pURI);
    virtual ~CFileListFiller();

public:
    TID GetID()         {   return mID; }

//actions
    void Start();
    void ItemCreated(const io::CURI &pURI);
    void ItemDeleted(const io::CURI &pURI);
    void Cancel();

protected:
//internal actions
    CListBox::SItem *CreateItemFor(const io::CFile&);
    void DoFill();
    void DoItemCreated(const io::CURI &pURI);
    void DoItemDeleted(const io::CURI &pURI);

    void AddAction(int,const io::CURI &pURI=io::CURI());
    void OnActionsThread();

public:
    UEvent<void(int,gui::CListBox::SItem**,bool)> eAdd;
    UEvent<void(std::wstring)> eRemove;

protected:
    CFileList *mFileList;
    TID mID;
    io::CURI mURI;
    io::CFolder mFolder;
    std::vector<io::CFile> mFiles;
    bool mCancel;
    thread *mActionsThread;

//other objects
    CSyncQueue<CFileListFillerAction*> mPendingActions;

    static TID mNextID;
};

/*namespace gui*/ } /*namespace buola*/ }

#endif
